﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WarehouseWebAPP.code.BLL;

namespace WarehouseWebAPP.Pages.user.Search_Pages
{
    public partial class SearchItem : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void SerialComboBox_DataBound(object sender, EventArgs e)
        {
            SerialComboBox.Items.Insert(0, new ListItem("", "%"));
        }

        protected void VendorComboBox_DataBound(object sender, EventArgs e)
        {
            VendorComboBox.Items.Insert(0, new ListItem("--ALL--", "%"));
        }

        protected void SupplierComboBox_DataBound(object sender, EventArgs e)
        {
            SupplierComboBox.Items.Insert(0, new ListItem("--ALL--", "%"));
        }

        protected void ItemGridView_DataBound(object sender, EventArgs e)
        {
            foreach (GridViewRow row in ItemGridView.Rows)
            {
                Label vendor = (Label)row.FindControl("VendorLabel");
                Label supplier = (Label)row.FindControl("SupplierLabel");

                if (vendor != null & supplier != null)
                {
                    VendorBLL vendorBLL = new VendorBLL();
                    SupplierBLL supplierBLL = new SupplierBLL();
                    try
                    {
                        vendor.Text = vendorBLL.VendorGetByNum(new Guid(vendor.Text))[0].vendor_name;
                        supplier.Text = supplierBLL.SupplierGetByNum(new Guid(supplier.Text))[0].supplier_name;
                    }
                    finally
                    {
                        //TODO
                        //we should add dispose here
                        // we need to add dispose function foreach bll
                        // or maybe the detailsview disposes alone ,
                        // need to check, because there exists disposing event
                    }
                }
            }
        }

        protected void ExcelButton_Click(object sender, EventArgs e)
        {
            Response.ClearHeaders();
            Response.AddHeader("content-disposition", "attachment;filename=DeliveryReport.xls");
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "application/vnd.xls";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            ItemGridView.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End();
        }

        public override void VerifyRenderingInServerForm(Control control)
        {
            return;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }



   
    }
}
